home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-07 | 1.7 KB | 57 lines | [TEXT/McSk] |
- ( SANETrig floating point trig for Pocket Forth 0.6 )
- forget task : task ; decimal
-
- : 0F< ( f -- flag ) ( true if f is less than zero )
- 0. fcompare >r fdrop fdrop r> 0< ;
- : K ( n -- n[mod[360]] ) ( keep n within one circle )
- 360. frem 0.0 fcompare
- 0< IF fdrop 360. THEN f+ ;
-
- 57.2957795131 fconstant DPR ( degrees per radian )
- : SIN ( deg -- sin[deg] ) dpr f/ fsin ;
- : COS ( deg -- cos[deg] ) dpr f/ fcos ;
-
- : ATAN ( fy fx -- atan[y/x] )
- fdup 3 froll f/
- fatn dpr f* ( degrees )
- fswap 0f< >r
- fdup 0f< IF ( atn is negative )
- r> IF ( y is negative )
- 360. f+ ( quadrant IV )
- ELSE ( y is positive )
- 180. f+ ( quadrant II )
- THEN
- ELSE ( atn is positive )
- r> IF ( y is negative )
- 180. f+ ( quadrant III )
- THEN ( quadrant I )
- THEN ;
-
- : ASIN ( f -- asin[f] )
- fdup fabs 1.16415321827e-10 fcompare ( -- x y 1e-10 flag )
- >r fdrop r> 0> IF ( -- x y )
- fdup 0.5 fcompare >r fdrop fdrop r> 0> IF
- 1. fswap f-
- fdup 2. f* fswap fdup f* f-
- ELSE
- 1. fswap fdup f* f-
- THEN
- fsqrt f/ fatn
- ELSE
- fdrop
- THEN
- dpr f* ; ( convert to degrees )
-
- : TEST ( test this out ) 4 fix
- 100 150 !pen 275 150 -to 275 75 -to 100 150 -to
- 277 120 !pen ." 3.0 cm." 170 162 !pen ." 7.5 cm."
- 128 148 !pen 7.5 3.0 atan f. 161 emit cr ;
-
- room page
- ( You have just added a quadrant correcting arctan function )
- ( and the arcsin function from page 71 of the Apple Numerics)
- ( Manual, 2nd Ed. See the SANETrig file for more information).
- ( bytes of dictionary space left. )
- test
-
-